package com.boom.controller;

import com.boom.pojo.Order;
import com.boom.service.OrderService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.UUID;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Resource
    private OrderService orderService;

    @PostMapping("/add")
    public String add(Order order, Model model){

        order.setOrderNo(UUID.randomUUID().toString());

        String body = "充值号码："+order.getPhone()+"，充值金额："+order.getAmount()+"元";

        order.setBody(body);
        order.setStatus(0); // 0未支付,1已支付

        int result = orderService.add(order);
        if (result>0){
            model.addAttribute("order",order);
            return "pay";
        }

        model.addAttribute("error", "下单失败");
        return "404";
    }
}
